<template>
	<view class="ordersmianbox">
		<qi_navigation />
			<qi_address :addressdata="data.address"  />
		<scroll-view scroll-y class="scroll">
			<view v-for="item in data.ordersdata" class="goodsdata">
				<view class="itemimg">
					<image :src="item.goods.cover_url" mode="widthFix"></image>
				</view>
				<view class="datanum">
					<view class="goodstitle">{{item.goods.title}}</view>
					<view class="itemprice">
						<view>价格:<text>{{item.price}}</text></view>
							<view>数量：<text>{{item.num}}</text></view>
						</view>
					</view>
			</view>
		</scroll-view>
		<view class="orbottom">
			<view>
				总价格:
				<text>${{ amount }}</text>
			</view>
			<view @tap="Tappaytest">支付</view>
			<!-- <view @tap="Tappay">获取二维码</view> -->
		</view>
	</view>
</template>

<script setup>
import {
	getpreview,
	getorders,
	getordersdetails,
	getpaytest,
	getpay
} from '@/http/api.js';
import { onMounted, reactive, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import qi_address from './qi_address.vue';
import {
		useStore
	} from 'vuex';
		const store = useStore();
const data = reactive({
	ordersdata: [],
	address: []
});
let amount = ref('');
let orderid = ref('');
onLoad(val => {
	let include = val;
	getdetails(val);
});
onMounted(() => {
	// data.ordersdata = store.state.qi_cart.getcartdata
	// console.log(data.ordersdata);
	// console.log(1111111111);
	getpreview().then(res=>{
		console.log(res);
	})
	// getorders().then(res=>{
	// 	console.log(res);
	// 	data.ordersdata = res.data
	// })
});
const getdetails = ({ id }) => {
	console.log(id);
	getordersdetails(id).then(res => {
		console.log(res);
		// 地址
		data.address = res.address;
		// 总价格
		amount.value = res.amount;
		orderid.value = res.id;
		// 商品
		data.ordersdata = res.orderDetails.data;
			console.log(store.state.qi_cart.getcartdata);
		console.log(data.ordersdata);
	});
};
const ordersdatas = val => {
	console.log(val);
};
// 支付
const Tappaytest = () => {
	getpaytest(orderid.value).then(res => {
		console.log(res);
		uni.switchTab({
			url: '/pages/cart/cart'
		});
	});
};
// 获取二维码
const Tappay = () => {
	console.log(212);
	getpay(orderid.value).then(res => {
		console.log(res);
	});
};
</script>

<style lang="scss">
	.goodstitle{
			// display: flex;?
		// width: 100%;
		
	}
	.itemprice{
		display: flex;
		// align-items: flex-end;
		justify-content: space-around;
		text{
		color: red;
		}
	}
	.goodsdata{
		display: flex;
		// justify-content: space-between;
		// margin-top: 20px;
		padding:  20px ;
		.itemimg{
			image{
				width: 200rpx;
			}
		}
		.datanum{
			width: 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			
		// 	width: 100%;
		// display: flex;
		// align-items: flex-end;
		// justify-content: space-around;
		}
	}
.ordersmianbox {
	position: relative;
	height: 100vh;
	// padding: 0 20px;
	.scroll {
		height: calc(100vh - 250px );
	}
	.orbottom {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		display: flex;
		height: 50px;
		align-items: center;
		background-color: #fff;
		justify-content: space-around;
		text {
			color: red;
			padding-left: 10px;
		}
	}
}
</style>
